package com.dragon.mmochat.model;

import java.util.ArrayList;
import java.util.List;

import com.dragon.mmochat.MmochatConstant;

public class MmochatNews implements Comparable<MmochatNews> {
	private static MmochatSerial serial = new MmochatSerial();
	public static int pageSize = 600;// 分页每页大小
	int id = 0;
	String title = "";// 标题
	String pubTime = "";// 发布时间
	List<String> content = new ArrayList<String>();// 详细内容，分页
	long createTime = System.currentTimeMillis();// 获取的时间
	int hit = 0;// 点击数

	public void createId() {
		id = serial.addAndGetSerialId();
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getPubTime() {
		return pubTime;
	}

	public void setPubTime(String pubTime) {
		this.pubTime = pubTime;
	}

	public List<String> getContent() {
		return content;
	}

	public void setContent(List<String> content) {
		this.content = content;
	}
	
	public int getPageNum(){
		return content.size();
	}

	public void setContent(String info) {
		if (info.length() < pageSize) {
			content.add(info);
		} else {
			int pageNum = (info.length() + pageSize - 1) / pageSize;
			for (int i = 0; i < pageNum; i++) {
				int beginIndex = i * pageSize;
				int endIndex = Math.min(beginIndex + pageSize, info.length());
				if (beginIndex < endIndex) {
					String sub = info.substring(beginIndex, endIndex);
					content.add(sub);
				}
			}
		}
	}

	public long getCreateTime() {
		return createTime;
	}

	public void setCreateTime(long createTime) {
		this.createTime = createTime;
	}

	public boolean isTimeOut() {
		return System.currentTimeMillis() - createTime > MmochatConstant.MS_PER_HOUR * 3;
	}

	public int getHit() {
		return hit;
	}

	public void setHit(int hit) {
		this.hit = hit;
	}

	public void addHit() {
		hit++;
	}

	@Override
	public int compareTo(MmochatNews arg0) {
		return arg0.getId() - id;
	}

}
